package main

import (
	"fmt"
	"mystruct"
)

func main() {
	root := mystruct.TreeNode{Value: 3}
	fmt.Println("root:", root)

	//无论是地址还是结构体本身都用.来访问成员
	root.Left = &mystruct.TreeNode{}
	fmt.Println("1 root's left:", root.Left)
	root.Left.SetTreeNodeValue(100)
	fmt.Println("2 root's left:", root.Left)
	root.Left.SetTreeNodeValue2(100)
	fmt.Println("3 root's left:", root.Left)

	root.Right = &mystruct.TreeNode{5, nil, nil}
	fmt.Println("4 root's right:", root.Right)

	root.Right.Left = new(mystruct.TreeNode)
	fmt.Println("root's right's left:", root.Right.Left)

	//为一个结构体定义方法必须在同一个包内，但可以在不同的文件中
	root.Left.Right = mystruct.InitTreeNode(2)
	fmt.Println("root's left's right:", root.Left.Right)

	fmt.Println()
	fmt.Println("root的遍历")
	root.Traversing()
	fmt.Println()

	//myTreeNode扩展了mystruct包中的TreeNode结构体
	mynode := mystruct.MyTreeNode{&root}
	fmt.Println("MyTreeNode的遍历")
	mynode.PostOrder()
	fmt.Println()

	mynode2 := mystruct.MyTreeNode2{&root}
	fmt.Println("MyTreeNode2的PostOrder遍历")
	mynode2.PostOrder() //调用MyTreeNode2的PostOrder方法
	fmt.Println()

	fmt.Println("MyTreeNode2（“子类”）的Traversing遍历")
	mynode2.Traversing() //调用MyTreeNode2的Traversing方法
	fmt.Println()

	fmt.Println("TreeNode（“父类”）的Traversing遍历")
	mynode2.TreeNode.Traversing() //调用TreeNode的Traversing方法
	fmt.Println()

	//baseRoot := &mystruct.TreeNode{}
	//myTreeNode2 := &mystruct.MyTreeNode2{&mystruct.TreeNode{Value: 50}}
	//baseRoot = myTreeNode2 //不能赋值，虽然看上去是父子关系，但实际是两种不同的类型。需要通过接口现。

}
